import request from 'plugin/axios'

export function getDepartList(data?: {
    parent_id?: number | null,
    name?:string,
    enabled?:number | undefined
}){
    return request({
        url:'/dept/list',
        data,
        method:'post'
    })
}

export function saveDepart(data:{
    id?:number | undefined,
    name:string,
    parent_id?:number | undefined,
    remark?:string,
    sort?:number | undefined,
    leader?:string,
    leader_phone?:string,
    enabled?:number | undefined
}){
    return request({
        url:'/dept/save',
        data,
        method:'post'
    })
}

export function deleteDepart(data:{
    id:number | undefined
}){
    return request({
        url:'/dept/delete',
        data,
        method:'post'
    })
}

export function getDepartDetail(params:{
    id:number | null
}){
    return request({
        url:`/dept/get/${params.id}`,
        params,
        method:'get'
    })
}

export function toggleDepart(data: {
    id:number | undefined,
    enabled:boolean
}){
    return request({
        url:'/dept/enable',
        data,
        method:'post'
    })
}

export function getAccountList(params:any){
    return request({
        url:'v1/agent/list',
        params,
        method:'post'
    })
}

export function getAccountDetail(params:{
    id:number
}){
    return request({
        url:`/user/get/${params.id}`,
        method:'get'
    })
}

export function saveAccount(data: {
    id?: number | undefined,
    name: string,
    mobile: string,
    account: string,
    password?: string,
    enabled: number | undefined,
    dept_id: number | undefined,
    role_list: string[] ,
}){
    return request({
        url:'/user/save',
        data,
        method:'post'
    })
}

export function toggleAccount(data: {
    id:number | undefined,
    enabled:boolean
}){
    return request({
        url:'/user/enable',
        data,
        method:'post'
    })
}

export function deleteAccount(data:{
    id:number | undefined
}){
    return request({
        url:'/user/delete',
        data,
        method:'post'
    })
}

export function resetAccountPassword(data : {
    id:number | undefined,
    password:string | undefined,
    password_confirm:string | undefined
}) {
    return request({
        url:'/user/resetPassword',
        data,
        method:'post'
    })
}

export function getRoleList(){
    return request({
        url:'/role/listTree',
        method:'post'
    })
}

export function saveRole(data: {
    id?: number | undefined,
    role_name: string,
    parent_id?: number | undefined,
    enabled:number
}){
    return request({
        url:'/role/save',
        method:'post',
        data,
    })
}

export function toggleRole(data: {
    id:number | undefined,
    enabled:boolean
}){
    return request({
        url:'/role/enable',
        data,
        method:'post'
    })
}

export function deleteRole(data:{
    id:number | undefined
}){
    return request({
        url:'/role/delete',
        data,
        method:'post'
    })
}

export function setRole(data:{
    role_id: number,
    resource_id_list: number[]
}){
    return request({
        url:'/role/set',
        data,
        method:'post'
    })
}

export function getMenuAndFnByRole(params: {
    role_id: number
}){
    return request({
        url:`/role/resourceList/${params.role_id}`,
        params,
        method:'get'
    })
}

export function saveRightsByRole(data:{
    role_id:number,
    resource_id_list:number[]
}){
    return request({
        url:'/role/set',
        method:'post',
        data,
    })
}

export function getDataRightsByRole(params: {
    role_id:number
}){
    return request({
        url:`/roleData/getDataByRoleId/${params.role_id}`,
        method:'get',
        params
    })
}

export function getUserListByRole(data : {
    role_id:number,
    current:number,
    size:number
}){
    return request({
        url:`/role/userList`,
        data,
        method:'post'
    })
}

export function getDataGroupList(data: {
    field_id:number,
    role_id:number
}){
    return request({
        url:'/roleData/getDataGroupList',
        data,
        method:'post'
    })
}

export function getDataGroupValueList(data: {
    field_id:number,
    role_id:number
}){
    return request({
        url:'/roleData/getDataGroupValueList',
        data,
        method: 'post'
    })
}

export function saveRoleData(data: {
    role_id:number,
    field_id:number,
    values:number[],
    group_ids:number[]
}){
    return request({
        url:'/roleData/save',
        data,
        method:'post'
    })
}



export function getGiveList(params: any):Promise<any>{
    return request({
        url:'v1/give/list',
        params,
        method:'get'
    })
}

export function getGiveDetail(params: any):Promise<any>{
    return request({
        url:'v1/give/detail/get',
        params,
        method:'get'
    })
}

export function addGive(data:any):Promise<any>{
    return request({
        url:'v1/give/add',
        data,
        method:'post'
    })
}

export function editGive(data:any):Promise<any>{
    return request({
        url:'v1/give/edit',
        data,
        method:'post'
    })
}

export function setGive(data:any):Promise<any>{
    return request({
        url:'v1/give/seller/set',
        data,
        method:'post'
    })
}

export function toggleGive(data:any):Promise<any>{
    return request({
        url:'v1/give/status/toggle',
        data,
        method:'post'
    })
}